# 使用Python 3.9官方镜像作为基础镜像
FROM harbor.derucci-smart.com/docker/python:3.9

# 设置工作目录
WORKDIR /app

# 设置环境变量
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

# # 安装系统依赖
# RUN apt-get update && apt-get install -y \
#     procps \
#     net-tools \
#     iputils-ping \
#     telnet \
#     curl \
#     tzdata \
#     && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
#     && rm -rf /var/lib/apt/lists/*

# 复制requirements文件并安装Python依赖
COPY requirements.txt .
RUN pip install -r requirements.txt --trusted-host 10.16.3.174 -i http://10.16.3.174:9081/repository/group-pypi/simple

# 复制应用程序文件
COPY agent.py .
COPY tools.py .
COPY api_server.py .
#COPY .env.example .env

# 创建非root用户
RUN useradd --create-home --shell /bin/bash agent
RUN chown -R agent:agent /app
USER agent

# 暴露API端口
EXPOSE 3030

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python3 -c "import requests; r=requests.get('http://localhost:3030/health', timeout=5); exit(0 if r.status_code==200 else 1)" || exit 1

# 启动命令
CMD ["python3", "agent.py"]